home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
304_01
/
roff58.c
< prev
next >
Wrap
Text File
|
1990-02-12
|
13KB
|
490 lines
/********************************************************/
/* ROFF5, Version 2.00 */
/* (c) 1983,4,8,9 by Ernest E. Bergmann */
/* 730 Seneca Street, Bethlehem, Pa. 18015 */
/* */
/* Permission is hereby granted for all commercial and */
/* non-commercial reproduction and distribution of this */
/* material provided this notice is included. */
/********************************************************/
#include <roff5.h>
#if (VERSION!=2) || (subVERSION!=00)
#error ***************This is version 2.00******************
#endif
/********************************************************/
char *fgets3()
{ int count,c,i,*pw;
char *cptr,*pc, *pc2;
ENTRY *pe;
char wbuf[LSZ],*fnd;
count = MAXLINE;
cptr = &LINE[0];
if ( (c=ngetc(ifp))==EOF) return (LIN=NULL);
do { if(c==ICVAL[0])/*need macro substitution*/
{for(i=0;ICVAL[0]!=(wbuf[i]=ngetc(ifp));i++)
{if(wbuf[i]=='\n')
{if(i) putback('\n');
break;
}
}
if(i)
{wbuf[i]='\0';
if (*wbuf=='\"') /*comment rest of line*/
{*cptr='\n';
*(++cptr)='\0';
do c=ngetc(ifp);
while((c!='\n')&&(c!=EOF));
return( LIN=LINE );
}
else if(readonly(wbuf)) ; /* handled as predefined */
else if(NULL!=(pw=(int *)find2(wbuf,&RLINK)))/*register?*/
{itoC(*pw,wbuf,*(FORMAT *)(pw+1));
pbstr(wbuf);
}
else if(NULL!=(fnd=find2(wbuf,&SLINK))) pbstr(fnd);
else{
char buff[128];
unsigned siz;
ENTRY *where;
pc=wbuf;
pe=(ENTRY *)buff;
pe->link=SLINK.link;
pc2=(char *)&(pe->ident);
transfer(&pc,&pc2,'\0');
fprintf(stderr,"%cPlease define <%s>:",
BELL,wbuf);
gets(wbuf);
pc=wbuf;
transfer(&pc,&pc2,'\0');
siz = pc2 - buff;
if (NULL==(where=(ENTRY *)malloc(siz)))
exitm("fgets3(): cannot malloc\n");
SLINK.link = (ENTRY *)memcpy(where,buff,siz);
pbstr(wbuf);
}
continue;
}
else if(*wbuf!='\n') putback(ICVAL[0]);
c=ngetc(ifp);
}
if ((*cptr++ = c) == '\n') break;
} while (count--&&(c=ngetc(ifp))!=EOF);
*cptr = '\0';
return (LIN=LINE);
}
/**************************************************************
performs the formatting command returned by comtyp1 -sets global
variables ( indenting, underlining, etc. )
"line" starts just after the ".".
**************************************************************/
void comand()
{CMD c_type; /* command type */
int arg_val; /* argument value, if any */
char arg_typ; /* relative (+ or -) or absolute or conditional? */
char wbuf[LSZ], *lptr;
int i;
c_type = comtyp1(LIN);
switch (c_type)
{case UNKNOWN :
fprintf(stderr, "UNKNOWN COMMAND: <%s>\n", LINE);
return;
case DOTDOT : break;/* ignore remark */
case IG : ignore(); break;
case FI : /* filled lines */
Brk();
FILL = YES;
break;
case NF : /* non-filled lines */
Brk();
FILL = NO;
break;
case NA : /* Not Adjust lines */
JUSTIFY = NO;
break;
case AD : /* ADjust lines */
adjust();
break;
case BR : /* just cause a break */
Brk();
break;
case LS : /* set line spacing value */
arg_val = get_val2(LIN, &arg_typ, &lptr );
setS(LSVAL, arg_val, arg_typ, LS_DEF, 1, HUGE );
break;
case TI : /* set temporary left indent */
Brk();
arg_val = get_val2( LIN, &arg_typ, &lptr );
set ( &TIVAL, arg_val, arg_typ, TI_DEF, 0, RMVAL );
break;
case M1: /* set topmost margin */
arg_val = get_val2( LIN, &arg_typ, &lptr );
setS( M1VAL, arg_val, arg_typ, M1_DEF,0,HUGE);
break;
case M2: /* set second top margin */
arg_val = get_val2( LIN, &arg_typ, &lptr );
setS( M2VAL, arg_val, arg_typ, M2_DEF,0,HUGE);
break;
case M3: /* set first bottom margin */
arg_val = get_val2( LIN, &arg_typ, &lptr );
setS( M3VAL, arg_val, arg_typ, M3_DEF,0,HUGE);
setTRAP();
break;
case M4: /* set bottom-most margin */
arg_val = get_val2( LIN, &arg_typ, &lptr );
setS(M4VAL, arg_val, arg_typ, M4_DEF,0,HUGE);
setTRAP();
break;
case CE : /* center next arg_val lines */
Brk();
arg_val = get_val2( LIN, &arg_typ, &lptr );
set ( &CEVAL, arg_val, arg_typ,CE_DEF,0, HUGE);
break;
case HE : /* get header title for pages */
gettl3 ( LIN, EHEAD, &EH2, &EH3 );
gettl3 ( LIN, OHEAD, &OH2, &OH3 );
break;
case OH : /*get odd header title*/
gettl3 ( LIN, OHEAD, &OH2, &OH3 );
break;
case EH : /*get even header title*/
gettl3 ( LIN, EHEAD, &EH2, &EH3 );
break;
case FO : /* get footer title for pages */
gettl3 ( LIN, EFOOT, &EF2, &EF3 );
gettl3 ( LIN, OFOOT, &OF2, &OF3 );
break;
case OF : /* get odd page footer title*/
gettl3 ( LIN, OFOOT, &OF2, &OF3 );
break;
case EF : /* get even page footer title*/
gettl3 ( LIN, EFOOT, &EF2, &EF3 );
break;
case SP : /* space down arg_val blank lines */
arg_val = get_val2( LIN, &arg_typ, &lptr );
set (&SPVAL, arg_val, arg_typ, 1, 0, HUGE);
*(--LIN)='\0';
space ( SPVAL );
break;
case GO : /*advance printer to absolute location*/
arg_val = get_val2( LIN, &arg_typ, &lptr );
if (arg_val>=VLINENO) break; /*already there*/
set (&SPVAL, arg_val, arg_typ, 1, 0, HUGE);
if ((SPVAL>PLINENO)&&!DIVERTING)
if (PLINENO) space ( SPVAL - VLINENO );
else space(SPVAL-M1VAL[0]-M2VAL[0]);
break;
case ST : /* stop(pause) at each page?*/
arg_val = get_val2( LIN, &arg_typ, &lptr );
set(&PAGESTOP,arg_val,'0',YES,NO,YES);
break;
case BP : /* set pageno arg_val - begin page */
Brk();
arg_val = get_val2( LIN, &arg_typ, &lptr );
if(((VLINENO<=0)||(VLINENO>=FOOTLOC))&&
(arg_val==NO_VAL)) break;
if ( VLINENO > 0 ) space (HUGE);
set(&CURPAG,arg_val,arg_typ,CURPAG+1,0,9999);
NEWPAG = CURPAG;
break;
case NE : /*"need"*/
arg_val = get_val2( LIN, &arg_typ, &lptr );
if (arg_val==NO_VAL) arg_val=2;/*default*/
need(arg_val);
break;
case PL : /* set page length */
arg_val = get_val2( LIN, &arg_typ, &lptr );
setS(PLVAL, arg_val, arg_typ, PL_DEF,
M1VAL[0]+M2VAL[0]+M3VAL[0]+M4VAL[0]+1,HUGE);
setTRAP();
break;
case FF : /*formfeed*/
arg_val = get_val2( LIN, &arg_typ, &lptr );
set(&FFEED,arg_val,'0',FF_DEF,NO,YES);
break;
case SC : /*space character*/
setchar(SCVAL,TRUE,SC_INI,BLANK,127);
break;
case AB : /*abort*/
gwLIN(wbuf); /*skip command*/
skip_blanks();
trunc_bl(LIN);
if(strlen(LIN)) fprintf(stderr,"\n%s\n",LIN);
else fprintf(stderr,"\n***USER ABORT***\n");
exit();
case TF : /*translate flag */
setchar(TFVAL,TRUE,TF_DEF,BLANK+1,127);
break;
case CF : /*character flag*/
setchar(CFVAL,TRUE,CF_DEF,BLANK+1,127);
break;
case IC : /*insert character for macro replace*/
setchar(ICVAL,TRUE,IC_DEF,BLANK+1,127);
break;
case OU : /*output code string*/
ocode(); break;
case FR : /*define fractional or whole line spacing code*/
getfr(); break;
case WH : when();
setTRAP();
break;
case CH : changetrap();
setTRAP();
break;
case IT : itset();
break;
case EM : EMset();
break;
case DT : dtset();
break;
case TL :title3(LIN,CURPAG,PAGFMT); break;
case DS : /*define string*/
insert(); break;
case DE : /*define macro*/
case AM : /*append macro*/
mappend(c_type);
break;
case NR : /*number register */
dovar(); break;
case DI : /*diversion to file*/
case DA :
dappend(c_type);
break;
case SO : /*source from file*/
source(); break;
case OT : /*Output Transaltion*/
getot(); break;
case TM : /*msg to terminal*/
gwLIN(wbuf); /*skip command*/
skip_blanks();
trunc_bl(LIN);
fprintf(stderr,"<%s>\n",LIN);
break;
case BJ : /*break with right justification*/
if(FILL)/*not applicable otherwise*/
{spread(OUTBUF,
min(RMVAL-TIVAL,MAXLINE-1)-OUTW+1,
OUTWRDS);
Brk();
}
break;
case AF : /*assign format to register variable*/
assignfmt();
break;
case CZ : /*substitute ^Z character in decimal*/
arg_val = get_val2( LIN, &arg_typ, &lptr );
set(&CZSUB,arg_val,'0',(int)CZSUB_DEF,0,255);
break;
case RL : /* Ruler Line similar to Wordstar for tabs*/
gwLIN(wbuf); /*skip c